
#include "Vector2D.h"
#include <cmath>
#include <iostream>

Vector2D::Vector2D() : x(0.0f), y(0.0f) {}
Vector2D::Vector2D(float init_x, float init_y) : x(init_x), y(init_y) {}
Vector2D::Vector2D(const Vector2D &var) : x(var.x), y(var.y) {}


void Vector2D::add(const Vector2D &var){
    x += var.x;
    y += var.y;
}

void Vector2D::scale(double scal){
    x *= scal;
    y *= scal;
}

float Vector2D::length(void) const {
    return sqrtf(x*x + y*y);
}

float Vector2D::length_2(void) const {
    return x*x + y*y;
}

float Vector2D::dist(const Vector2D &var) const {
    Vector2D vec(x-var.x, y-var.y);
    return vec.length();
}

float Vector2D::dotProduct(const Vector2D &var) const {
    return x*var.x + y*var.y;
}    

void Vector2D::normalise(void){
    float length_i = 1.0f/length();
    x *= length_i;
    y *= length_i;
}

void Vector2D::rotate(float angle){
    float rads = M_PI/180.0f * angle;
    float nx = x*cosf(rads) - y*sinf(rads);
    float ny = y*cosf(rads) + x*sinf(rads);
    x = nx;
    y = ny;
}

float Vector2D::angleBetween(const Vector2D &var) const {
    return acosf(dotProduct(var)) * 180.0f/M_PI;
}

void Vector2D::printString(void) const {
    std::cerr << "Vector2D (" << x << ", " << y << ")" << std::endl;
    return;
}

